home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / util / pack / xpk_Source.lha / xpk_Source / shell / xBench.c < prev    next >
C/C++ Source or Header  |  1996-12-06  |  4KB  |  208 lines

  1. #define NAME     "xBench"
  2. #define REVISION "1"
  3.  
  4. /* Programmheader
  5.  
  6.     Name:        xBench
  7.     Author:        SDI (before 1.1 Urban Dominik Müller)
  8.     Distribution:    PD
  9.     Description:    xpk benchmark utility
  10.     Compileropts:    -
  11.     Linkeropts:    -l xpkmaster
  12.     Linkeropts SAS: LIB LIB:scm.lib
  13.  
  14.  1.1   29.11.96 : added version string
  15. */
  16.  
  17. #include "SDI_defines.h"
  18. #define SDI_TO_ANSI
  19. #include "SDI_ASM_STD_protos.h"
  20. #include <pragma/exec_lib.h>
  21. #include <pragma/dos_lib.h>
  22. #include <pragma/xpkmaster_lib.h>
  23. #include <pragma/timer_lib.h>
  24. #include <exec/memory.h>
  25. #include <exec/devices.h>
  26.  
  27. #ifdef __MAXON__
  28.   #define __asm
  29.   #define __saveds
  30. #endif
  31.  
  32. #define THREE_BUFS    0
  33. #define NOCRC        0
  34.  
  35. struct timerequest timerequest;
  36. struct Library *TimerBase = NULL;
  37. struct Library *XpkBase = NULL;
  38. BPTR fh = 0;
  39.  
  40. UBYTE errbuf[XPKERRMSGSIZE + 1];    /* +1 to make room for '\n'        */
  41. STRPTR Password = 0;
  42. STRPTR buf1 = 0, buf2 = 0, buf3 = 0;
  43. LONG bufsize;
  44.  
  45. void end(STRPTR str)
  46. {
  47.   if(fh)        Close(fh);
  48.   if(buf3)        FreeMem(buf3, bufsize);
  49.   if(buf2)        FreeMem(buf2, bufsize);
  50.   if(buf1)        FreeMem(buf1, bufsize);
  51.   if(TimerBase)        CloseDevice((struct IORequest *) & timerequest);
  52.   if(XpkBase)        CloseLibrary(XpkBase);
  53.   if(str)        printf ("%s\n", str);
  54.  
  55.   exit (0);
  56. }
  57.  
  58. void init(void)
  59. {
  60.   if(OpenDevice("timer.device", 0, (struct IORequest *) & timerequest, 0))
  61.     end("Can't open timer.device");
  62.  
  63.   TimerBase = &timerequest.tr_node.io_Device->dd_Library;
  64.  
  65.   if(!(XpkBase = OpenLibrary (XPKNAME, 0)))
  66.     end("Can't open " XPKNAME);
  67. }
  68.  
  69. void testfile(STRPTR packer, STRPTR file)
  70. {
  71.   struct EClockVal eval1, eval2;
  72.   struct FileInfoBlock fib;
  73.   ULONG freq, ulen, ulen2, clen, ctime, utime;
  74.   LONG cf;
  75.  
  76.   if(!(fh = Open(file, MODE_OLDFILE)))
  77.     end("Cannot open input file");
  78.  
  79.   if(!(ExamineFH (fh, &fib)))
  80.     end("Failed to ExamineFH input file");
  81.  
  82.   bufsize = fib.fib_Size + fib.fib_Size / 32 + 2 * XPK_MARGIN;
  83.  
  84.   if(!(buf1 = (STRPTR) AllocMem(bufsize, MEMF_FAST)))
  85.     end("Out of memory");
  86.  
  87.   if(!(buf2 = (STRPTR) AllocMem(bufsize, MEMF_FAST)))
  88.     end("Out of memory");
  89.  
  90. #if THREE_BUFS
  91.   if(!(buf3 = (STRPTR) AllocMem(bufsize, MEMF_FAST)))
  92.     end("Out of memory");
  93. #endif
  94.  
  95.   ulen = Read(fh, buf1, fib.fib_Size);
  96.  
  97.   if(ulen != fib.fib_Size)
  98.     end("Could not read whole file with one Read()");
  99.  
  100.   Close(fh);
  101.   fh = 0;
  102.  
  103.   /*--------------------------------------------------------*/
  104.  
  105.   Forbid ();
  106.   freq = ReadEClock (&eval1);
  107.   if(XpkPackTags(XPK_InBuf, buf1,
  108.          XPK_InLen, ulen,
  109.          XPK_OutBuf, buf2,
  110.          XPK_OutBufLen, bufsize,
  111.          XPK_GetOutLen, &clen,
  112.          XPK_GetError, errbuf,
  113.          XPK_Password, Password,
  114.          XPK_PackMethod, packer,
  115.          TAG_DONE))
  116.   {
  117.     Permit();
  118.     end(errbuf);
  119.   }
  120.  
  121.   ReadEClock(&eval2);
  122.   Permit();
  123.   ctime = eval2.ev_lo - eval1.ev_lo;
  124.  
  125.   /*--------------------------------------------------------*/
  126.  
  127.   Forbid();
  128.   ReadEClock(&eval1);
  129.  
  130.   if(XpkUnpackTags(XPK_InBuf, buf2,
  131.            XPK_InLen, clen,
  132. #if THREE_BUFS
  133.            XPK_OutBuf, buf3,
  134. #else
  135.            XPK_OutBuf, buf1,
  136. #endif
  137.            XPK_OutBufLen, bufsize,
  138.            XPK_GetOutLen, &ulen2,
  139.            XPK_GetError, errbuf,
  140. #if NOCRC
  141.            XPK_NoCRC, TRUE,
  142. #endif
  143.            XPK_Password, Password,
  144.            TAG_DONE))
  145.   {
  146.     Permit();
  147.     end(errbuf);
  148.   }
  149.  
  150.   ReadEClock(&eval2);
  151.   Permit();
  152.   utime = eval2.ev_lo - eval1.ev_lo;
  153.  
  154.   /*--------------------------------------------------------*/
  155.  
  156.   cf = 1000 - 1000 * clen / ulen;
  157.  
  158.   if(cf < 0)
  159.     cf = 0;
  160.  
  161.   printf("%-8s   %6ld %6ld %2ld.%ld%%    %3ld.%02ld %7ld     %2ld.%02ld %7ld\n",
  162.       packer,
  163.       ulen, clen, cf / 10, cf % 10,
  164.       ctime / freq, (100 * (ctime % freq)) / freq, (int) ((double) freq * (double) ulen / (double) ctime),
  165.       utime / freq, (100 * (utime % freq)) / freq, (int) ((double) freq * (double) ulen / (double) utime)
  166.     );
  167.  
  168.   if(ulen != ulen2)
  169.   {
  170.     printf("decompressed length is %ld !!!\n", ulen2);
  171.   }
  172.  
  173. #if THREE_BUFS
  174.   if(buf3)
  175.   {
  176.     FreeMem(buf3, bufsize);
  177.     buf3 = 0;
  178.   }
  179. #endif
  180.   if(buf2)
  181.   {
  182.     FreeMem(buf2, bufsize);
  183.     buf2 = 0;
  184.   }
  185.   if(buf1)
  186.   {
  187.     FreeMem (buf1, bufsize);
  188.     buf1 = 0;
  189.   }
  190. }
  191.  
  192. main(int argc, char *argv[])
  193. {
  194.   LONG i = 1;
  195.  
  196.   if(!strcmp (argv[1], "-p"))
  197.     Password = "testpw", i++;
  198.  
  199.   init();
  200.  
  201.   printf("Warning: Have to Forbid() task rescheduling for accurate measurements.\n");
  202.   printf("Packer      UComp   Comp    CF     CTime    CSpd     UTime    USpd\n");
  203.   for(; i < argc - 1; i++)
  204.     testfile (argv[i], argv[argc - 1]);
  205.  
  206.   end(NULL);
  207. }
  208.